#include "MetaObjectIO.h"
#include "MetaObjectOperation.h"

namespace gitstore {

CObjectOperation::CObjectOperation() {

}

CObjectOperation::~CObjectOperation() {

}

ErrorStatus CObjectOperation::setMainBranch(Object &object, const std::string br_name) {
    object.main_branch = br_name;
    return Success;
}

ErrorStatus CObjectOperation::setNote(Object &object, const std::string& note) {
    object.note = note;
    return Success;
}

ErrorStatus CObjectOperation::create(const std::string& obj_name, const std::string& ds_note,
                                      const std::string& br_name, const std::string& br_note,
                                      int type, int subtype, std::string& version, Object& object) {
    time_t t;
    t=time(&t);
    object.date = t;
    object.name = obj_name;
    object.note = ds_note;
//    object.branches.emplace_back(br_name);
    object.main_branch = br_name;
    object.type = type;
    object.subtype = type;
//    object.nodes.emplace_back(version);
    return Success;
}



CBranchOperation::CBranchOperation() {

}

CBranchOperation::~CBranchOperation() {

}

ErrorStatus CBranchOperation::setVersion(Branch& branch, const std::string& version) {
    branch.cur_version = version;
    return Success;
}

ErrorStatus CBranchOperation::setNote(Branch& branch, const std::string& note) {
    branch.note = note;
    return Success;
}

ErrorStatus CBranchOperation::create(const std::string& obj_name, const std::string& br_name, const std::string& br_note, const std::string& version, int type, Branch& branch) {
    branch.obj_name = obj_name;
    branch.name = br_name;
    branch.note = br_note;
    branch.type = type;
    branch.cur_version = version;
    time_t t;
    t=time(&t);
    branch.date = t;
    return Success;
}




CNodeOperation::CNodeOperation() {

}

CNodeOperation::~CNodeOperation() {

}

ErrorStatus CNodeOperation::create(const std::string& obj_name, const std::string& version, const std::string& note, int type, const std::vector<std::string>& parents, Node& node) {
    node.obj_name = obj_name;
    node.version = version;
    node.parents.insert(node.parents.begin(), parents.begin(), parents.end());
//    std::copy(parents.begin(), parents.end(), node.parents.begin());
    node.note = note;
    node.type = type;
    time_t t;
    t=time(&t);
    node.date = t;
    return Success;
}

ErrorStatus CNodeOperation::addChild(Node& node, const std::string& child_version) {
    node.children.emplace_back(child_version);
    return Success;
}

}
